﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified"
           elementFormDefault="qualified"
           targetNamespace= "http://dataaccessor.codeplex.com/xsd/T-SQL"
           xmlns= "http://dataaccessor.codeplex.com/xsd/T-SQL"
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="TSQL">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="Statement">
          <xs:complexType>
            <xs:sequence>
              <xs:element maxOccurs="1" minOccurs="1" name="Command">
                <xs:complexType>
                  <xs:simpleContent>
                    <xs:extension base="xs:string">
                      <xs:attribute name="Type" type="CommandTypeRestriction" use="optional" default="Text"/>
                      <xs:attribute name="Timeout" type="xs:int" use="optional" default="30"/>
                    </xs:extension>
                  </xs:simpleContent>
                </xs:complexType>
              </xs:element>
              <xs:element minOccurs="0" name="Params">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="Param">
                      <xs:complexType>
                        <xs:attribute name="Name" type="xs:string" use="required" />
                        <xs:attribute name="DataType" type="ParameterDataTypeRestriction" use="required" />
                        <xs:attribute name="Length" type="xs:int" use="optional" default="0" />
                        <xs:attribute name="Direction" type="ParameterDirectionRestriction" use="optional" default="Input" />
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="Name" type="xs:string" use="required" />
            <xs:attribute name="MappingType" type="xs:string" use="optional" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <!--命令类型的取值范围定义-->
  <xs:simpleType name="CommandTypeRestriction">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Text"/>
      <xs:enumeration value="StoredProcedure"/>
      <xs:enumeration value="TableDirect"/>
    </xs:restriction>
  </xs:simpleType>

  <!--命令方向的取值范围定义-->
  <xs:simpleType name="ParameterDirectionRestriction">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Input"/>
      <xs:enumeration value="Output"/>
      <xs:enumeration value="InputOutput"/>
      <xs:enumeration value="ReturnValue"/>
    </xs:restriction>
  </xs:simpleType>

  <!--数据类型的取值范围定义-->
  <xs:simpleType name="ParameterDataTypeRestriction">
    <xs:restriction base="xs:string">
      <xs:enumeration value="AnsiString"/>
      <xs:enumeration value="Binary"/>
      <xs:enumeration value="Byte"/>
      <xs:enumeration value="Boolean"/>
      <xs:enumeration value="Currency"/>
      <xs:enumeration value="Date"/>
      <xs:enumeration value="DateTime"/>
      <xs:enumeration value="Decimal"/>
      <xs:enumeration value="Double"/>
      <xs:enumeration value="Guid"/>
      <xs:enumeration value="Int16"/>
      <xs:enumeration value="Int32"/>
      <xs:enumeration value="Int64"/>
      <xs:enumeration value="Object"/>
      <xs:enumeration value="SByte"/>
      <xs:enumeration value="Single"/>
      <xs:enumeration value="String"/>
      <xs:enumeration value="Time"/>
      <xs:enumeration value="UInt16"/>
      <xs:enumeration value="UInt32"/>
      <xs:enumeration value="UInt64"/>
      <xs:enumeration value="VarNumeric"/>
      <xs:enumeration value="AnsiStringFixedLength"/>
      <xs:enumeration value="StringFixedLength"/>
      <xs:enumeration value="Xml"/>
      <xs:enumeration value="DateTime2"/>
      <xs:enumeration value="DateTimeOffset"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>